Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lit/reactive-element

Package Overview
Dependencies
Maintainers
9
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lit/reactive-element

A simple low level base class for creating fast, lightweight web components

  • 1.6.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created

What is @lit/reactive-element?

The @lit/reactive-element package provides a base class for creating lightweight, reactive components. It is part of the Lit library, which is designed for building fast, lightweight web components. The reactive-element package focuses on the reactive system that powers Lit components, allowing developers to create and manage properties that automatically update the component when changed.

What are @lit/reactive-element's main functionalities?

Reactive properties

This feature allows the creation of reactive properties that trigger updates to the component when their values change. The example defines a custom element with a reactive property 'name'. When 'name' changes, the 'updated' method logs the new value.

import { ReactiveElement } from '@lit/reactive-element';

class MyElement extends ReactiveElement {
  static properties = {
    name: {type: String}
  };

  constructor() {
    super();
    this.name = 'Lit';
  }

  updated(changedProperties) {
    if (changedProperties.has('name')) {
      console.log(`Name updated to: ${this.name}`);
    }
  }
}
customElements.define('my-element', MyElement);

Lifecycle callbacks

Lifecycle callbacks provide hooks into the component's lifecycle. This example shows how to use 'connectedCallback' and 'disconnectedCallback' to perform actions when the element is added to or removed from the DOM.

import { ReactiveElement } from '@lit/reactive-element';

class MyElement extends ReactiveElement {
  connectedCallback() {
    super.connectedCallback();
    console.log('Element added to the page.');
  }

  disconnectedCallback() {
    super.disconnectedCallback();
    console.log('Element removed from the page.');
  }
}
customElements.define('my-element', MyElement);

Other packages similar to @lit/reactive-element

FAQs

Package last updated on 02 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc